import logging

from cibynet.lib.base import *

log = logging.getLogger(__name__)

class BuildingsController(AdminController):
  """REST Controller styled on the Atom Publishing Protocol"""

  def index(self, format='html'):
    """GET /buildings: All items in the collection."""
    buildings_q = meta.Session.query(Building)
    c.buildings = buildings_q.all()
    return render('/buildings/index.mako')

  def create(self):
    """POST /buildings: Create a new item."""
    pass

  def new(self, format='html'):
    """GET /buildings/new: Form to create a new item."""
    pass

  def update(self, id):
    """PUT /buildings/id: Update an existing item."""
    pass

  def delete(self, id):
    """DELETE /buildings/id: Delete an existing item."""
    pass

  def show(self, id, format='html'):
    """GET /buildings/id: Show a specific item."""
    buildings_q = meta.Session.query(Building)
    try:
      c.building = buildings_q.filter(Building.id == id).one()
    except:
      abort(404)
    else:
      return render('/buildings/detail.mako')

  def edit(self, id, format='html'):
    """GET /buildings/id;edit: Form to edit an existing item."""
    pass
